﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginByAjax.aspx.cs" Inherits="LoginByAjax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="Scripts/common.js"></script>
    <script type="text/javascript">
        var xhr;
        window.onload = function () {
            xhr = createXmlHttp();
            gel("btnL").onclick = loginByAjax;

        }

        function loginByAjax() {
            var uName = gel("txtUName").value;
            var uPwd = gel("txtPwd").value;
            var urlStr = "LoginByAjax.aspx";
            var data = "un=" + uName + "&up=" + uPwd;
            alert("Name:"+uName);
            alert("PWD" + uPwd);
            alert("data:"+data);
            xhr.open("POST", urlStr, true);
            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function () {
                gel("msgDiv").innerHTML = "登录中......";
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        var reponseText = xhr.responseText;
                        if (reponseText == "1") {
                            alert("登录成功！");
                            window.location = "Default.aspx";
                        } else {
                            alert("登录失败！");
                        }
                    }
                    else {
                        alert("服务器错误！xhr.status=" + xhr.status);
                    }
                }

            }
            xhr.send(data);
        }
    
    
    
    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="msgDiv"><img id="msgImg" src="" /></div>
    <div>
        <input type="text" id="txtUName" name="txtUName" value="" /><br />
        <input type="text" id="txtPwd" name="txtPwd" value="" /><br />
        <input type="button" id="btnL" name="txtPwd" value="Login" /><br />
    </div>


    </form>
</body>
</html>
